var chalk = require("chalk");
var fs = require('fs');
var path = require('path');
var config = require('@ionic/app-scripts/config/webpack.config.js');

var mode = process.env.mode || "dev";// 模式  开发还是生产还是测试 dev prod test
var project = process.env.project || "";// 项目名称

console.log("mode : " + mode);
console.log("project : " + project);

var alias = {
  "@providers": path.resolve('src/providers'),
  "@pipes": path.resolve('src/pipes'),
  "@env/environment": path.resolve(environmentPath(mode, project)),
  "@common": path.resolve('src/common'),
  "@components": path.resolve('src/components')
};

config[process.env.IONIC_ENV].resolve.alias = alias;

function environmentPath(mode, project) {
  var filePath = "src/environments/environment.";
  if (mode) {
    filePath += (mode + ".")
  }
  if (project != "") {
    filePath += (project + ".")
  }
  filePath += "ts";
  if (!fs.existsSync(filePath)) {
    console.log(chalk.red('\n' + filePath + ' does not exist!'));
  } else {
    console.log(filePath);
    return filePath;
  }
}

module.exports = function () {
  return config;
};

